package com.ufo.store.management.utils;

import android.app.Activity;
import android.os.Build;
import android.util.DisplayMetrics;
import android.view.Display;

public class ScreenUtil {
    /**
     * 得到屏幕长宽
     *
     * @param activity
     */
    public static int[] getScreenSize(Activity activity) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        Display display = activity.getWindowManager().getDefaultDisplay();
        display.getMetrics(displayMetrics);
        int width = displayMetrics.widthPixels;
        int height = displayMetrics.heightPixels;
        if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT < 17) {
            try {
                height = (Integer) display.getClass().getMethod("getRawHeight").invoke(display);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (height == 0) {
            height = displayMetrics.heightPixels;
        }
        int[] sizes = new int[2];
        sizes[0] = width;
        sizes[1] = height;
        return sizes;
    }
}
